package com.oracle.application.controller;


import com.oracle.application.entity.vo.*;
import com.oracle.application.service.IOrdersService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author qhy
 * @since 2021-06-24
 */
@RestController
@RequestMapping("/orders")
@Slf4j
public class OrdersController {

    @Autowired
    private IOrdersService iOrdersService;

    //订单确认的订单信息
    @GetMapping("/confirm")
    public R<OrderConfirmVo> confirm(List<CartVo> cartVos){

        OrderConfirmVo orderConfirmVo = iOrdersService.creareOrderConfirm(cartVos);

        return new R<OrderConfirmVo>(200,"success",orderConfirmVo);
    }


    /*
    订单
     */
    @PostMapping("/submit")
    public R submit(@RequestBody OrderSbumitVo orderSbumitVo){
        log.info("订单提交后的订单信息内容参数:{}",orderSbumitVo);
        Map<String,Object> rMap = new HashMap<>();
        try {
            rMap = this.iOrdersService.submitOrder(orderSbumitVo);
            if (rMap.get("code")!=null&&!rMap.get("code").equals("500")){
                return new R(201,"请不要重复创建订单",null);
            }
        }catch (Exception e){

        }
     OrdersVo ordersVo=(OrdersVo) rMap.get("data");
        log.info("data:{}",ordersVo);
        return new R(200,"ok",ordersVo);

    }
}
